//
//  ViewController.swift
//  weatherProject
//
//  Created by shaorui on 15/9/20.
//  Copyright (c) 2015年 weatherProject. All rights reserved.
//

import UIKit


class ViewController: UIViewController {

    
    @IBOutlet var textView: UITextView!
    @IBAction func  buttionAction (senderDesc:AnyObject)
    {
    
        println("\(senderDesc)");
        self.textView.text = nil;
        self.loadWeatherInit()

        
        

    
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
//    self.loadWeatherInit()

            // Do any additional setup after loading the view, typically from a nib.
    }
    
    func loadWeatherInit()
    {
        
        
        //var dataJson =  NSURL( string:"http://m.weather.com.cn/atad/101010100.html")
        
        
        var url = NSURL(string: "http://m.weather.com.cn/atad/101010100.html")
        
        //@availability(iOS, introduced=2.0, deprecated=8.0, message="Use +dataWithContentsOfURL:options:error: and NSDataReadingMappedIfSafe or NSDataReadingMappedAlways instead.")
        
        
        var data = NSData(contentsOfURL:url!, options: NSDataReadingOptions.DataReadingUncached, error: nil)
        
        //        var data = NSData.ininc( url,options:NSDataReadingOptions.DataReadingUncached, error: nil)
        var json:AnyObject = NSJSONSerialization.JSONObjectWithData(data! ,options: NSJSONReadingOptions.AllowFragments, error: nil)!;
        
        
        var weartheInfo: AnyObject? = json.objectForKey("weatherinfo")
        var wearthCity: AnyObject? = weartheInfo?.objectForKey("city")
        var wearthCityen: AnyObject? = weartheInfo?.objectForKey("city_en")
        var wearthCityID: AnyObject? = weartheInfo?.objectForKey("cityid")
        var wearthCityDate: AnyObject? = weartheInfo?.objectForKey("date_y")
        var wearthCityfchh: AnyObject? = weartheInfo?.objectForKey("fchh")
        
        var wearthValues: AnyObject? = weartheInfo?.valueForKey("fl1");
        
        var  week:AnyObject? = weartheInfo?.objectForKey("week")
        var  index_d:AnyObject? = weartheInfo?.objectForKey("index_d")

        println("is wearthValues \(weartheInfo)");
        
        
        println("is json \(wearthCityID)");
        
        println("is wearthCityDate \(wearthCityfchh)");
        
        println("is wearthCity \(wearthCity)");
        println("is wearthCity \(wearthCityDate)");
        println("is week \(week)")
        println("is index_d")
        self.textView.text = "城市名称:\(wearthCity)\n当前日期:\(wearthCityDate)\n周几\(week)\n 穿衣介绍\(index_d)"

     
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

